#!/bin/bash

LOG_DIR="/home/cys/www/script/logs"
# 日志文件名包含日期，每次执行的日志前添加时间戳
LOG_FILE="${LOG_DIR}/backup_log_39_$(date +%Y-%m-%d).log"
mkdir -p "${LOG_DIR}"

# 记录开始时间
echo "[$(date +%Y-%m-%d_%H:%M:%S)] 开始执行 Python 脚本" >> "${LOG_FILE}"

TARGET_IP="184.168.29.39"

if pgrep -f "backup_monitor_log.sh $TARGET_IP" > /dev/null; then
    echo "backup_monitor_log.sh $TARGET_IP 已经在运行，退出"  >> "${LOG_FILE}"
    exit 1
else
    echo "启动 backup_monitor_log.sh..."  >> "${LOG_FILE}"
    # 执行 Python 脚本，输出包含时间戳
    sh /home/cys/www/script/ch_recollect_log/backup_monitor_log.sh $TARGET_IP 2>&1 | while read line; do
        echo "[$(date +%Y-%m-%d_%H:%M:%S)] $line" >> "${LOG_FILE}"
    done
fi



# 记录结束时间
echo "[$(date +%Y-%m-%d_%H:%M:%S)] shell 脚本执行结束" >> "${LOG_FILE}"
echo "日志已写入 ${LOG_FILE}"
